import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  JoinColumn,
} from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("social_relations")
@ManualTimestamp()
export class SocialRelationEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId" })
  characterId!: number;

  @Column("int", { nullable: true, comment: "配偶角色ID" })
  spouseId!: number;

  @Column("varchar", { length: 64, nullable: true, comment: "配偶名称" })
  spouseName!: string;

  @Column("int", { nullable: true, comment: "师傅角色ID" })
  masterId!: number;

  @Column("varchar", { length: 64, nullable: true, comment: "师傅名称" })
  masterName!: string;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    comment: "更新时间",
    nullable: true,
  })
  updated_at!: Date | null;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.socialRelations)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
